//==============================================================================
//
//               Copyright (C) 2004  Dick van Oudheusden
//  
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this library; if not, write to the Free
// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//==============================================================================
// 
//  $Date: 2004-11-25 17:35:46 $ $Revision: 1.5 $
//
//==============================================================================

#include "ofc/DLog.h"
#include "ofc/DFile.h"
#include "ofc/DTextWritableLogger.h"
#include "ofc/DTimer.h"

#include "DTest.h"

//-Compound--------------------------------------------------------------------

void DTextWritableLogger_test()
{
  DFile               *file      = [DFile new];
  DTextWritableLogger *logger    = [DTextWritableLogger new];

  STARTTEST();

  if ([file open :"logging.txt" :"w"])
  {
    int i;
    
    [logger writer :file];

    dlogger(logger);
    
    dlog(DLOG_PANIC,    "Panic level");
    dlog(DLOG_ALERT,    "Alert level:%d", 120);
    // Repeated message
    for (i = 0; i < 250; i++)
    {
      dlog(DLOG_CRITICAL, "Critical level"); 
    }
    dlog(DLOG_ERROR,    "Error level");
    dlog(DLOG_WARNING,  "Warning level");
    dlog(DLOG_NOTICE,   "Info level");
    dlog(DLOG_DEBUG,    "Debug level");

    [DTimer delay :123];
    
    dlogmask(DLOG_ALERT|DLOG_CRITICAL|DLOG_WARNING|DLOG_DEBUG);
    
    dlog(DLOG_PANIC,    "Bitwise Masked panic level");
    dlog(DLOG_ALERT,    "Bitwise Masked alert level:%d", 120);
    dlog(DLOG_CRITICAL, "Bitwise Masked critical level");
    dlog(DLOG_ERROR,    "Bitwise Masked error level");
    dlog(DLOG_WARNING,  "Bitwise Masked warning level");
    dlog(DLOG_NOTICE,   "Bitwise Masked info level");
    dlog(DLOG_DEBUG,    "Bitwise Masked debug level");
    
    [DTimer delay :234];
    
    dlogrange(DLOG_ALERT,DLOG_INFO);

    dlog(DLOG_PANIC,    "Ranged Masked panic level");
    dlog(DLOG_ALERT,    "Ranged Masked alert level:%d", 120);
    dlog(DLOG_CRITICAL, "Ranged Masked critical level");
    dlog(DLOG_ERROR,    "Ranged Masked error level");
    dlog(DLOG_WARNING,  "Ranged Masked warning level");
    dlog(DLOG_NOTICE,   "Ranged Masked info level");
    dlog(DLOG_DEBUG,    "Ranged Masked debug level");

    dlogger(nil);
    
    [file close];
  }
  
  STOPTEST();

  [logger free];
  [file   free];
}

